home *** CD-ROM | disk | FTP | other *** search
- #include "proctext.h"
- #include "noise.h"
-
- static float valueTab[TABSIZE];
-
- static void valueTabInit(int seed);
- static float vlattice(int ix, int iy, int iz);
-
- float
- vnoise(float x, float y, float z)
- {
- int ix, iy, iz;
- int i, j, k;
- float fx, fy, fz;
- float xknots[4], yknots[4], zknots[4];
- static int initialized = 0;
-
- if (!initialized) {
- valueTabInit(665);
- initialized = 1;
- }
-
- ix = FLOOR(x);
- fx = x - ix;
-
- iy = FLOOR(y);
- fy = y - iy;
-
- iz = FLOOR(z);
- fz = z - iz;
-
- for (k = -1; k <= 2; k++) {
- for (j = -1; j <= 2; j++) {
- for (i = -1; i <= 2; i++)
- xknots[i+1] = vlattice(ix+i,iy+j,iz+k);
- yknots[j+1] = spline(fx, 4, xknots);
- }
- zknots[k+1] = spline(fy, 4, yknots);
- }
- return spline(fz, 4, zknots);
- }
-
- static void
- valueTabInit(int seed)
- {
- float *table = valueTab;
- int i;
- extern long random();
- extern long srandom();
-
-
- srandom(seed);
- for(i = 0; i < TABSIZE; i++)
- *table++ = 1. - 2.*RANDNBR;
- }
-
- static float
- vlattice(int ix, int iy, int iz)
- {
- return valueTab[INDEX(ix,iy,iz)];
- }
-